<?php
include dirname(dirname(__FILE__)).'/admin-verify.php';
include dirname(__FILE__)."/functions.php";
$ret=getPlaceApplyTable();		
?>
<html>
	<head>
		<title>场地申请管理</title>
		<?php include dirname(dirname(dirname(__FILE__))).'/include/common-header.php' ?>
		<script type="text/javascript">
		$(document).ready(function (){
			$(".apply").click(function(){
				var val=$.trim($(this).val());
				$("#data").val(val);
				var num=$.trim($(this).next().val());
				if(num>0){

					$("#handle-apply-form").submit();
				}

				
			});

			$(".show").click(function(){
				var val=$.trim($(this).val());
				$("#data").val(val);
				
					$("#handle-apply-form").submit();
		
				
			});
		});
		</script>
	</head>
	<body>
	
		<div class="container">	
					<table class="table table-striped table-bordered table-hover table-condensed default-table">
			  <tr>
			  	<th>申请情况</th>
			  	<th>8:00~10:00</th>
			  	<th>10:00~12:00</th>
			  	<th>12:00~14:00</th>
			  	<th>14:00~16:00</th>
			  	<th>16:00~18:00</th>
			  	<th>18:00~20:00</th>
			  	<th>20:00~22:00</th>
			  </tr>
			  
			  	<?php
			  	$i=0; 
			  	while ($row=mysql_fetch_array($ret))
			  	{	echo "<tr>";
			  		
			 	 	echo "<th>".$row["date"]."</th>";
			  		$arr=json_decode($row["table_content"],true);
			  		
			  		foreach ($arr as $key => $value){
						if ($value>0) {

							$ret1=getSUserById($value);
							$row1=mysql_fetch_array($ret1);						
							echo "<th>".'<button class="btn btn-primary show" value='.'"'.$row["date"].','.$key.'"'.'>'.$row1['username'].'</button>'."</th>";
						}else{
						if ($i==0||$i==1) {
							
								echo "<th>".'<button class="btn btn-default disabled" >截止操作</button>'."</th>";
							
						
						}else {
							$num=applyCheck($row["date"], $key);		
							echo "<th>".'<button class="btn btn-primary apply" value='.'"'.$row["date"].','.$key.'"'.'>'."待处理".$num.'</button>'.'<input  type="hidden" value="'.$num.'"/>'."</th>";
						
						
						
						}
			  		}	
			  		}						  					  		
			  		echo "</tr>";
			  		$i++;
			  	}?>
			 
			</table>
			 <form class="form-horizontal col-md-offset-3" id="handle-apply-form" role="form" method="post" action="apply-manage.php">
			  <input name="submited" type="hidden" value="1">
			  <input name="data" id="data" type="hidden" value=""/>
			</form>
		
				
		
	</div>	
	</body>
</html>